package com.youren.health.controller;

import com.youren.health.constant.MessageConstant;
import com.youren.health.entity.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: health_parent
 * @author: You_ren_a
 * @create: 2020-12-01 09:53
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    @PostMapping("/getLoginUsername")
    public Result getLoginUsername() {
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return new Result(true, MessageConstant.GET_USERNAME_FAIL, user.getUsername());
    }
}
